package com.example.demo.sort;

import java.util.Random;

/**
 * <pre>
 *  描述:
 * </pre>
 *
 * @author godelgnis(wujiaer)
 * @version 1.0.0
 * @date 2021/12/9 20:35
 */
public class ArrayUtil {

    public static int[] random(int capacity, int bound) {
        if (capacity < 0) {
            return null;
        }
        int[] array = new int[capacity];
        Random random = new Random();
        for (int i = 0; i < capacity; i++) {
            array[i] = random.nextInt(bound);
        }
        return array;
    }

    public static int[] clone(int[] array) {
        if (array == null) {
            return null;
        }
        int[] result = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i];
        }
        return result;
    }

    public static boolean equals(int[] arr1, int[] arr2) {
        if (arr1 == null) {
            return arr2 == null;
        }
        if (arr2 == null) {
            return false;
        }
        if (arr1.length != arr2.length) {
            return false;
        }
        for (int i = 0; i < arr2.length; i++) {
            if (arr1[i] != arr2[i]) {
                return false;
            }
        }
        return true;
    }
}
